package com.diycode.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.diycode.entity.Tickets;
import com.diycode.mapper.TicketsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author diycode
 */
@Service
public class TicketsService extends ServiceImpl<TicketsMapper, Tickets> {
    @Resource
    TicketsMapper mapper;

    //删除
    public int delete(Integer id) {
        return mapper.deleteById(id);
    }

    //批量删除
    public int delete(String ids) {
        return mapper.deleteBatchIds(Arrays.asList(ids.split(",")));
    }

    //根据id查询
    public Tickets detail(Integer id) {
        return mapper.selectById(id);
    }

    //查询
    public PageInfo<Tickets> query(Tickets entity) {
        if (entity != null && entity.getPage() != null) {
            PageHelper.startPage(entity.getPage(), entity.getLimit());
        }
        return new PageInfo<>(mapper.query(entity));
    }

    public List<Tickets> findByTrainID(Integer trainID) {
        Tickets query=new Tickets();
        query.setTrainID(trainID);
        return mapper.query(query);
    }
}
